package com.example.aabb;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;

public class BillAdapter extends RecyclerView.Adapter<BillAdapter.BillViewHolder> {
    private List<Bill2> billList;

    public BillAdapter(List<Bill2> billList) {
        this.billList = billList;
    }

    @Override
    public BillViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_bill, parent, false);
        return new BillViewHolder(view);
    }

    @Override
    public void onBindViewHolder(BillViewHolder holder, int position) {
        Bill2 bill = billList.get(position);
        holder.icon.setImageResource(bill.getIcon());
        holder.description.setText(bill.getDescription());
        holder.amount.setText(String.valueOf(bill.getAmount()));
    }

    @Override
    public int getItemCount() {
        return billList.size();
    }

    public static class BillViewHolder extends RecyclerView.ViewHolder {
        ImageView icon;
        TextView description;
        TextView amount;

        public BillViewHolder(View itemView) {
            super(itemView);
            icon = itemView.findViewById(R.id.icon_image);
            description = itemView.findViewById(R.id.description_text);
            amount = itemView.findViewById(R.id.amount_text);
        }
    }
}